/** 类装饰器 **/
// 1. 不带参数的
function FirstClassDecorator(targetClass: any) {
  let targetClassObj = new targetClass('加入购物车')
  targetClassObj.buy()
  console.log('targetClass.name', targetClass.name)
}

// 2. 带参数的
function SecondClassDecorator(params: any) {
  console.log('带参: ', params)
  return function (targetClass: any) {
    let targetClassObj = new targetClass('立即下单')
    targetClassObj.buy()
    console.log('targetClass.name', targetClass.name)
  }
}

// 注意这里有多个装饰器，执行顺序是从下往上，即先执行SecondClassDecorator 再执行 FirstClassDecorator
@FirstClassDecorator
@SecondClassDecorator('我是用来修饰装饰器的参数')
class CustomerService {
  name: string = '下单'
  constructor(name_: string) {
    this.name = name_
  }
  buy() {
    console.log(this.name)
  }
  placeOrder() { // 下单
    console.log(this.name + '下单购买')
  }
}

